<?php
  include_once('../conn.php');

  // 借阅管理更新
  $id = $_POST['id'];
  $book_id = $_POST['book_id'];
  $book_count = $_POST['book_count'];
  $apply_num = $_POST['apply_num'];
  $apply_statue = $_POST['apply_statue'];

  if($apply_statue == 1) {
    $book_count = $book_count - $apply_num; // 通过借阅申请，将书籍总数量减至借阅后数量
    // 更新书籍数量信息
    $sql = "update book set book_count = $book_count where id = $book_id";
    $result = mysqli_query($conn, $sql);
  }
  // 更新借阅信息
  $sql = "update apply set 
    apply_statue = $apply_statue 
    where id = $id";
  // echo $sql;
  $result = mysqli_query($conn, $sql);
  if($result) {
    alert('处理成功', 'apply_list.php');
  } else {
    alert('处理失败', 'apply_list.php');
  }

  mysqli_close($conn);
?>